Option Explicit
Private diceArray()
Private iDicePool As Long
Private iBigSuccess As Long
Private iSuccess As Long
Private diceList As Object



Function WodDice(dicepool As Long, condition As String, Optional min As Integer = 1)
    'dicepool 投几个骰子
    'condition,成功条件
    'min 函数是投出最小值,为了拯救非酋用的
    Randomize
    '定义变量及数组列表
    
    Dim i_ As Long
    Set diceList = CreateObject("System.Collections.ArrayList")
    
    
    iDicePool = dicepool
    
    Do Until (iDicePool <= 0)
        Call WodDice_tail(iDicePool, condition, min)
    Loop
    iSuccess = iSuccess + iBigSuccess
    diceArray = diceList.toarray
    Set diceList = Nothing
End Function


Function WodDice_tail(dicepool As Long, condition As String, Optional min As Integer = 1)
    'dicepool 投几个骰子
    'condition,成功条件
    'min 函数是投出最小值,为了拯救非酋用的
    Dim dice_number As Integer
    dice_number = WorksheetFunction.RandBetween(min, 10)
    
    If dice_number = 10 Then
        
        diceList.Add dice_number
        iBigSuccess = iBigSuccess + 1
        
        
    ElseIf Application.Evaluate(dice_number & condition) Then
        dicepool = dicepool - 1
        iDicePool = dicepool
        iSuccess = iSuccess + 1
        diceList.Add dice_number
        
    Else
        dicepool = dicepool - 1
        iDicePool = dicepool
        diceList.Add dice_number
    End If
    
End Function


Function getDiceList()
    getDiceList = diceArray
End Function

Function getBigSucceed()
    getBigSucceed = iBigSuccess
End Function

Function getSucceed()
    getSucceed = iSuccess
End Function


Sub test_timer()
    Dim t!, s$
    t = Timer
    [1:2].ClearContents
    Call WodDice(1000, ">7")
    
    Sheets("Sheet1").Cells(1, 1).Resize(UBound(getDiceList), 1) = Application.Transpose(getDiceList)
    Sheets("Sheet1").Cells(1, 2) = getSucceed
    Sheets("Sheet1").Cells(2, 2) = getBigSucceed
    Debug.Print Timer - t
    iSuccess = 0
    iBigSuccess = 0
    Erase diceArray
End Sub

